/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gblend.largegraph.structure;

import java.util.HashMap;
import java.util.Vector;

/**
 * Used to easily process & construct the freq frag id lists.
 * The ID used here is the index of the fragment when they are read into freqgraphs
 * in BuildInfreqIndex
 * @author HO HOANG HUNG
 */
public class FreqFragSet {
    int maxesize = 0;
    //frequent fragments group according to their edges size, value in vector is
    //their indices in freqgraphs vector.
    private HashMap<Integer,Vector<Integer>> ffset= new HashMap<Integer,Vector<Integer>>();
    //For 1-edge fragments, mapped to their indices in freqgraphs
    private HashMap<String,Integer> oneedgeset = new HashMap<String,Integer>();
    private HashMap<Integer,Vector<Integer>> parentlist = new HashMap<Integer,Vector<Integer>>();

    public void addFragment(int index,int edgesize){
        if(edgesize>maxesize){
            maxesize=edgesize;
        }
        Vector<Integer> ss = ffset.get(edgesize);
        if(ss==null){
            ss = new Vector<Integer>();
            ss.add(index);
            ffset.put(edgesize, ss);
        }else{
            ss.add(index);
        }
    }

    public void addParents(int childindex, int pindex){
         Vector<Integer> ss = parentlist.get(childindex);
        if(ss==null){
            ss = new Vector<Integer>();
            ss.add(pindex);
            parentlist.put(childindex, ss);
        }else{
            ss.add(pindex);
        }
    }
    public void addOneEdgeFrag(int index,String cam){
        oneedgeset.put(cam, index);
    }

    public int getOneEdgeFrag(String cam) throws Exception{
        Integer ab=oneedgeset.get(cam);
        if(ab==null){
            throw new Exception("Cannot find this CAM code");
        }
        return ab;
    }

    public int getNumOfEdgeSize(){
        return maxesize;
    }

    public Integer[] getFragments(int edgesize){
        return ffset.get(edgesize).toArray(new Integer[0]);
    }

    /**
     * get the parent pair list of the fragment at this index
     * @param index
     * @return
     */
    public Vector<Integer> getParents(int index){
        Vector<Integer> res = parentlist.get(index);
        /*int[][] resa = new int[res.size()/2][2];
        for(int i=0;i<resa.length;i++){
            resa[i][0] = res.get(2*i);
            resa[i][1]=res.get(2*i+1);
        }*/
        return res;
    }
}
